import 'dart:io';
import 'package:flutter/foundation.dart';
//import 'package:wechat_kit/wechat_kit.dart';
import '../../utils/k_log.dart';
import '../plugin/ts_plugin.dart';

class AppConst {
  ///域名
  static const String baseUrl = "https://api.juzhangit.com/";
  static const String pathSegmentsUrl = ""; //PathSegments

  //用户协议
  static String serviceUrl = Platform.isAndroid
      ? (isCSJ
          ? "https://app.dingjiwangluo.com/protocol/mould/agreement/e45a3e3d-2ffb-4fc9-8d74-5d44237a7e26.html"
          : "https://app.dingjiwangluo.com/protocol/mould/agreement/ee82a6df-6e3d-41ea-a07f-27ec2e940b6d.html")
      : "https://alidocs.dingtalk.com/i/p/rO5pXBkoLLgWm7ZvZBGLRKYqj7J0yXL1";

  //隐私政策
  static String policyUrl = Platform.isAndroid
      ? (isCSJ
          ? "https://app.dingjiwangluo.com/protocol/mould/privacy/736c10b7-c389-48b0-a3d1-a215f96b6860.html"
          : "https://app.dingjiwangluo.com/protocol/mould/privacy/7a60871e-23a6-462b-8fa9-76c43c7911df.html")
      : "https://alidocs.dingtalk.com/i/p/rO5pXBkoLLgWm7ZvZBGLRKYWa0pRjXL1";

  //友盟
  static const String umengAppKey = "66da645250a80a550eda9129";

  //鼎级AppID
  static const String djAppId =
      "a92c610a9d289818df4c3d435ac62a38e81bad5efabbf2b9e8";

  //微信APPID
  static const String wxAppId = "wx27fe28f98d74e5cb";

  //图标
  static final String appLogo = Platform.isAndroid
      ? "android/app/src/main/res/mipmap-xxhdpi/icon_app_logo.png"
      : "ios/Runner/Assets.xcassets/AppIcon.appiconset/icon_app_logo.png";

  //启动图
  static final String appStartBg = Platform.isAndroid
      ? "android/app/src/main/res/mipmap-xxhdpi/bg_launcher.png"
      : "ios/Runner/Assets.xcassets/LaunchImage.imageset/bg_launcher.png";

  //平台名称
  static String channel = "HUAWEI";

  //是否是CSJ
  static bool isCSJ = channel.toUpperCase() == "CSJ";

  //初始化
  static Future initAppConst() async {
    //日志打印
    KLog.init(isDebug: kDebugMode);

    if (Platform.isIOS) {
      channel = "APPLE";
    }

    if (Platform.isAndroid) {
      var channel = await TsPlugin.getChannel();
      if (channel.isNotEmpty) {
        AppConst.channel = channel.toUpperCase();
        KLog.d("AppConfigLog 平台 ${AppConst.channel}");
      }
      //android 应用名称
      //AppConst.appName = await TsPlugin.getAppName();
      //自动构建用户协议
      var serviceUrl = await TsPlugin.getServiceUrl();
      if (serviceUrl.isNotEmpty) {
        AppConst.serviceUrl = serviceUrl;
      }
      //自动构建隐私协议
      var policyUrl = await TsPlugin.getPolicyUrl();
      if (policyUrl.isNotEmpty) {
        AppConst.policyUrl = policyUrl;
      }
      KLog.d("AppConfigLog android端 serviceUrl: ${AppConst.serviceUrl}");
      KLog.d("AppConfigLog android端 policyUrl: ${AppConst.policyUrl}");
    }
  }

  //初始化wx
  static initWechat() async {
  //   if (Platform.isIOS) {
  //     await WechatKitPlatform.instance.registerApp(
  //       appId: wxAppId,
  //       universalLink: "https://your.univerallink.com/link/",
  //     );
  //   }
  //   if (Platform.isAndroid) {
  //     await WechatKitPlatform.instance.registerApp(
  //       appId: wxAppId,
  //       universalLink: null,
  //     );
  //   }
  }
}
